package com.dksidana.java.jdbc.pool;

import java.sql.Connection;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.dksidana.java.pool.ObjectTimestampPair;
import com.dksidana.java.pool.PoolableObjectFactory;

public class ConnectionFactory implements PoolableObjectFactory<Connection,SQLException>{
	
	DataSource dataSource;
	public ConnectionFactory(DataSource dataSource) {
		this.dataSource=dataSource;
	}
	public void detroyObject(Connection k) throws SQLException {
		k.close();
	}

	public Connection makeObject() throws SQLException {
		return dataSource.getConnection();
	}

	public boolean validateObject(ObjectTimestampPair<Connection> pair) throws SQLException {
		return !pair.getObject().isClosed();
		
	}

}
